home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3 / CHAPTE16 / MIDIDEV.C < prev    next >
C/C++ Source or Header  |  1996-04-28  |  6KB  |  210 lines

  1.  
  2. #include <windows.h>
  3. #include "MidiDev.h"
  4.  
  5. #if defined (WIN32)
  6.     #define IS_WIN32 TRUE
  7. #else
  8.     #define IS_WIN32 FALSE
  9. #endif
  10.  
  11. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  12. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  13. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  14.  
  15. HINSTANCE hInst;   // current instance
  16.  
  17. LPCTSTR lpszAppName = "MyApp";
  18. LPCTSTR lpszTitle   = "midiInOutDevCaps"; 
  19.  
  20. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  21.  
  22.  
  23. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  24.                       LPTSTR lpCmdLine, int nCmdShow)
  25. {
  26.    MSG      msg;
  27.    HWND     hWnd; 
  28.    WNDCLASS wc;
  29.  
  30.    wc.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  31.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  32.    wc.cbClsExtra    = 0;                      
  33.    wc.cbWndExtra    = 0;                      
  34.    wc.hInstance     = hInstance;              
  35.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  36.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  37.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  38.    wc.lpszMenuName  = lpszAppName;              
  39.    wc.lpszClassName = lpszAppName;              
  40.  
  41.    if ( IS_WIN95 )
  42.    {
  43.       if ( !RegisterWin95( &wc ) )
  44.          return( FALSE );
  45.    }
  46.    else if ( !RegisterClass( &wc ) )
  47.       return( FALSE );
  48.  
  49.    hInst = hInstance; 
  50.  
  51.    hWnd = CreateWindow( lpszAppName, 
  52.                         lpszTitle,    
  53.                         WS_OVERLAPPEDWINDOW | WS_VSCROLL, 
  54.                         CW_USEDEFAULT, 0, 
  55.                         CW_USEDEFAULT, 0,  
  56.                         NULL,              
  57.                         NULL,              
  58.                         hInstance,         
  59.                         NULL               
  60.                       );
  61.  
  62.    if ( !hWnd ) 
  63.       return( FALSE );
  64.  
  65.    ShowWindow( hWnd, nCmdShow ); 
  66.    UpdateWindow( hWnd );         
  67.  
  68.    while( GetMessage( &msg, NULL, 0, 0) )   
  69.    {
  70.       TranslateMessage( &msg ); 
  71.       DispatchMessage( &msg );  
  72.    }
  73.  
  74.    return( msg.wParam ); 
  75. }
  76.  
  77.  
  78. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  79. {
  80.     WNDCLASSEX wcex;
  81.  
  82.    wcex.style         = lpwc->style;
  83.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  84.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  85.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  86.    wcex.hInstance     = lpwc->hInstance;
  87.    wcex.hIcon         = lpwc->hIcon;
  88.    wcex.hCursor       = lpwc->hCursor;
  89.    wcex.hbrBackground = lpwc->hbrBackground;
  90.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  91.    wcex.lpszClassName = lpwc->lpszClassName;
  92.  
  93.    // Added elements for Windows 95.
  94.    //...............................
  95.    wcex.cbSize = sizeof(WNDCLASSEX);
  96.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  97.                             IMAGE_ICON, 16, 16,
  98.                             LR_DEFAULTCOLOR );
  99.             
  100.    return RegisterClassEx( &wcex );
  101. }
  102.  
  103.  
  104. #define MSG_LEN          1024
  105.  
  106. char     msg[MSG_LEN+1];
  107.  
  108. HWND     hListBox = NULL;
  109. MMRESULT rc;
  110.  
  111.  
  112. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  113. {
  114.    switch( uMsg )
  115.    {
  116.       case WM_CREATE :
  117.               // create ListBox
  118.               //...............
  119.  
  120.               hListBox = CreateWindow( "LISTBOX", "",    
  121.                                        WS_CHILD | LBS_NOTIFY | WS_VSCROLL | WS_BORDER | 
  122.                                        WS_VISIBLE | LBS_NOINTEGRALHEIGHT, 
  123.                                        0, 0, 
  124.                                        0, 0,  
  125.                                        hWnd,              
  126.                                        (HMENU)101,              
  127.                                        hInst,         
  128.                                        NULL );
  129.               break;
  130.  
  131.       case WM_SIZE :
  132.               MoveWindow( hListBox, 0, 0, 
  133.                           LOWORD( lParam ), 
  134.                           HIWORD( lParam ), TRUE );
  135.               break;
  136.  
  137.       case WM_COMMAND :
  138.               switch( LOWORD( wParam ) )
  139.               {
  140.                  case IDM_TEST :
  141.                         {
  142.                            UINT nDevId;
  143.                            MIDIINCAPS mic;
  144.                            MIDIOUTCAPS moc;
  145.  
  146.                            SendMessage(hListBox, LB_RESETCONTENT, 0, 0);
  147.  
  148.                            for (nDevId = 0; nDevId < midiInGetNumDevs(); nDevId++)
  149.                            {
  150.                               midiInGetDevCaps(nDevId, &mic, sizeof(mic));
  151.                               SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)mic.szPname);  
  152.                            }
  153.  
  154.                            for (nDevId = 0; nDevId < midiOutGetNumDevs(); nDevId++)
  155.                            {
  156.                               midiOutGetDevCaps(nDevId, &moc, sizeof(moc));
  157.                               SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)moc.szPname);  
  158.                            }
  159.  
  160.                         }
  161.                         break;
  162.  
  163.                  case IDM_ABOUT :
  164.                         DialogBox( hInst, "AboutBox", hWnd, About );
  165.                         break;
  166.  
  167.                  case IDM_EXIT :
  168.                         DestroyWindow( hWnd );
  169.                         break;
  170.               }
  171.               break;
  172.      
  173.       case WM_DESTROY :
  174.               PostQuitMessage(0);
  175.               break;
  176.  
  177.       default :
  178.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  179.    }
  180.  
  181.    return( 0L );               
  182. }
  183.  
  184.  
  185. LRESULT CALLBACK About( HWND hDlg,           
  186.                         UINT message,        
  187.                         WPARAM wParam,       
  188.                         LPARAM lParam)
  189. {
  190.    switch (message) 
  191.    {
  192.        case WM_INITDIALOG: 
  193.                return (TRUE);
  194.  
  195.        case WM_COMMAND:                              
  196.                if (   LOWORD(wParam) == IDOK         
  197.                    || LOWORD(wParam) == IDCANCEL)    
  198.                {
  199.                        EndDialog(hDlg, TRUE);        
  200.                        return (TRUE);
  201.                }
  202.                break;
  203.    }
  204.  
  205.    return (FALSE); 
  206. }
  207.  
  208.  
  209.  
  210.